<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" isELIgnored="false" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="/WEB-INF/airCompany.tld" prefix="cc"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>航空公司走势对比（航班）——恒拓运价魔方</title>
<%-- <script type="text/javascript" src="${pageContext.request.contextPath}/fare/js/show.js"></script>--%>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/datePicker/WdatePicker.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/lib/ligerUI/js/ligerui.min.js"></script>
<link href="<%=request.getContextPath() %>/fare/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/FusionCharts/FusionCharts.js"></script>
<link href="<%=request.getContextPath() %>/fare/css/base.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/jsFile/common.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/jsFile/multiblepicker.js"></script>

<%--<link href='<%=request.getContextPath()%>/fare/js/cityquery/cityquery.css' rel="stylesheet" type="text/css" />
 <script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/citylist.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/querycity.js'></script> --%>
<link rev="stylesheet" media="all" href="<%=request.getContextPath() %>/fare/css/form_style.css" type="text/css" rel="stylesheet">

<!-- 圆角文本框 -->
<link href="<%=request.getContextPath() %>/fare/css/htc/htc.css" rel="stylesheet" type="text/css" />
<script type="text/javascript"
	src="<%=request.getContextPath() %>/jsFile/wait/js/wait.js"></script>	

<script>
/**
 * 生成一个未来天数的日期字符串
 */
function generateTimeByFutrueDay(day){
	if(!/^\d+$/.test(day)){day=0;}
	var now=new Date();
	now.setDate(now.getDate()+day);
	var year=now.getFullYear();
	var month=now.getMonth()+1;
	month=month<10?"0"+month:month+"";
	var date=now.getDate();
	date=date<10?"0"+date:date+"";
	return year+"-"+month+"-"+date;
}
$(document).ready(function(){
	//定义一个全局变量
	window.CHENKED_FLIGHTS=new Array();
	$('#depCity').querycity({'data':citysFlight,'tabs':labelFromcity});
	$('#arrCity').querycity({'data':citysFlight,'tabs':labelFromcity});
	$('#flightStartDate').val(generateTimeByFutrueDay(0));
	$('#flightEndDate').val(generateTimeByFutrueDay(30));
	
	
	$("#futureDay").click(function(){//未来天数被点击
		$('#flightStartDate').val("");
		$('#flightEndDate').val("");
		$("input[name='flightDateRadio'][type='radio'][value='2']").attr('checked',true);
	});
	$("#flightStartDate").click(function(){//出发/到达城市被点击
		$("input[name='flightDateRadio'][type='radio'][value='1']").attr('checked',true);
		$("#futureDay").val("");
		if($(this).val()=="" && $("#flightEndDate").val()=="" ){
			$('#flightStartDate').val(generateTimeByFutrueDay(0));
			$('#flightEndDate').val(generateTimeByFutrueDay(30));
		}
	});
	$("#flightEndDate").click(function(){//出发/到达城市被点击
		$("input[name='flightDateRadio'][type='radio'][value='1']").attr('checked',true);
		$("#futureDay").val("");
		if($(this).val()=="" && $("#flightStartDate").val()==""){
			$('#flightStartDate').val(generateTimeByFutrueDay(0));
			$('#flightEndDate').val(generateTimeByFutrueDay(30));
		}
	});
	
	
	$("input[name='flightDateRadio'][type='radio']").change(function(){
		if($(this).val()==1){
			$("#futureDay").val("");
			$('#flightStartDate').val(generateTimeByFutrueDay(0));
			$('#flightEndDate').val(generateTimeByFutrueDay(30));
		}else{
			$('#flightStartDate').val("");
			$('#flightEndDate').val("");
		}
	});
	
	var obj=window.dialogArguments;
	if(obj && obj.href_state=='href'){
		$("input[type='text']").css({
			color:"black"
		});
		$("#depCityCode").val(obj.href_depCity);
		$("#arrCityCode").val(obj.href_arrCity);
		 
		//$("#contrastAirLine").val(obj.href_airLine);
		//alert(obj.href_airLine);
		//alert(obj.href_channels);
		//$("#channel").val(obj.href_channels);
		CHENKED_FLIGHTS.push(obj.href_airLine);
		showCheckedFlightData();//刷新航班界面
		/* $("#dataSourceHbaseKey").val(obj.href_channels); */
		$("#dataSourceHbaseKey option").each(function() {  
	        if ($(this).text() == obj.href_channels) { 
	                $(this).attr("selected", "selected");  
	               return ;
	            }  
	        }); 
		//启动查询
		ajaxLoad();
		myScroll();
		
	}else{
		$("#dataSourceHbaseKey")[0].selectedIndex=0;
	}/* else{
		$("#channel")[0].selectedIndex=0;
	} */
	
	$("#depCity").css({
		color:'black'
	});
	$("#arrCity").css({
		color:'black'
	});
	
	
	
	
	$("input[name='airLineDateType'][type='radio']").change(function(){
		if($(this).val()=="1"){
			
			if($("#airLineEndDate").val()==""){
				$("#airLineEndDate").val(generateTimeByFutrueDay(30));
			}
			if($("#airLineStartDate").val()==""){
				$("#airLineStartDate").val(currentDate());
			}
			$("#futureDays1").val("");
		}else{
			$("#airLineStartDate").val("");
			$("#airLineEndDate").val("");
		}
	});
	
	$("#airLineStartDate").click(function(){
		$("#futureDays1").val("");
		
		$("input[name='airLineDateType'][type='radio'][value='1']").attr("checked",true);
		if($("#airLineStartDate").val()==""){
			$("#airLineStartDate").val(currentDate());
		}
		if($("#airLineEndDate").val()==""){
			$("#airLineEndDate").val(generateTimeByFutrueDay(30));
		}
	});
	$("#airLineEndDate").click(function(){
		$("#futureDays1").val("");
		
		$("input[name='airLineDateType'][type='radio'][value='1']").attr("checked",true);
		if($("#airLineStartDate").val()==""){
			$("#airLineStartDate").val(currentDate());
		}
		if($("#airLineEndDate").val()==""){
			$("#airLineEndDate").val(generateTimeByFutrueDay(30));
		}
	});
	$("#futureDays1").click(function(){
		$("#airLineStartDate").val("");
		$("#airLineEndDate").val("");
		$("input[name='airLineDateType'][type='radio'][value='2']").attr("checked",true);
	});
	
	//$("#airLineCompany")[0].selectedIndex=0;
	//$("#airLineCompany").attr("disabled",true);
	//$("#channel")[0].selectedIndex=0;
	$("#airLineEndDate").val(generateTimeByFutrueDay(30));
});

function ajaxLoad(){
	var url="<%=request.getContextPath() %>/airCompanyTrendContrastFlightAction!analyse.action";
	$.ajax({
		url:url,
		data:$("#queryForm").serialize(),
		cache : false, 
		async : true,
	    type : "POST",
	    dataType:'html',
	    beforeSend:function(){FDCWait.show();},
	    success:function(data){
	    	var chart2 = new FusionCharts("<%=request.getContextPath() %>/FusionCharts/MSLine.swf", "chart2Id", 990, "450");
			chart2.setDataXML(data);
			chart2.render("chartContainer");
	    },
	    error:function(){ },
	    complete:function(){ FDCWait.hide();}
	});
}
//改变城市的时候触发
function changeCity(){
	CHENKED_FLIGHTS=[];
	showCheckedFlightData();
}

//查询的验证
function queryValidate(){
	if(validateFlightCity()==true 
			&& validateFlightDate()==true
			&&  validateCompareFlightNo()==true
			&& validateCompareFlightNo()==true){
		ajaxLoad();
		
	}
}
//验证航班
function validateFlightCity(){
	var depCity =$('#depCity').val();
    var arrCity =$('#arrCity').val();
    if(depCity==''||depCity=='中文/拼音' || arrCity==''||arrCity=='中文/拼音'){
		    alert("请先选择航线！");
	        return false;	     
	}
    if(depCity == arrCity){
    	alert("请选择不同的对比航线");
    	return false;
    }
    return true;
}
//验证航班日期
function validateFlightDate(){
	var value=$("input[name='flightDateRadio'][type='radio']:checked").val();
	if(value=='1'){
		var startdate = $('#flightStartDate').val();
		var enddate = $('#flightEndDate').val();
		
		if(startdate=="" || enddate==""){
			alert("您选择的是按【航班日期】查询，请输入填写完整正确的查询日期");
			return false;
		}	
		var s_date = new Date(startdate.replace(/-/g,"/"));
	    var e_date = new Date(enddate.replace(/-/g,"/"));
	    var time1 = s_date.getTime();
		var time2 = e_date.getTime();
		if(time1>time2){
			alert("航班日期起始时间不能大于航班结束时间");
			return false;
		}
	}else if(value=='2'){//未来天数
		var futureDays =$('#futureDay').val();
		if(futureDays==""){
			alert("您选择的是按【未来天数】查询，请输入未来天数");
			return false;
		}
		if(futureDays > 30){
			alert("请输入不多于未来30天(包含本日)的天数");
			return false;
		}
	}else{
		return false;
	}
	return true;
}
//验证要比较的航班
function validateCompareFlightNo(){
	if($("input[name='compareFlights'][type='checkbox'][checked]").length==0){
		alert("请选择要比较的航班");
		return false;
	}
	return true;
}


function myScroll(y){
	if(!y){y=100}
	if(y>=350){return;}
	scrollTo(0,y);
	y+=10;
	window.setTimeout(function(){
		myScroll(y);
	},30);
}

function showFlightinfoPage(){	
    if(validateFlightCity()!=true){
    	return;
    }
    var w_w=500;
	var w_h=370;
	var iTop = (window.screen.availHeight-30-w_h)/2; //获得窗口的垂直位置;
	var iLeft = (window.screen.availWidth-10-w_w)/2; //获得窗口的水平位置;
	var url="<%=request.getContextPath() %>/airCompanyTrendContrastFlightAction!toAddFlightInfoJsp.action";	
	var obj={//带过去下个页面的参数数据
			CHENKED_FLIGHTS:CHENKED_FLIGHTS,
			arrCity:$("#arrCity").val(),
			depCity:$("#depCity").val(),
			pWin:window//把父窗口放过去
	};

	 window.showModalDialog(url,obj,
				'dialogHeight='+w_h+
				'px;dialogWidth='+w_w+
				'px;dialogLeft='+iLeft+
				'px;dialogTop='+iTop+
				'px;status=no;scroll=yes;resizable=no;help=no,center=yes'
				); 
   
}
//展示选择的数据
function showCheckedFlightData(){
	var table=$("#checked_flights_table");
	$(table).empty();
	var rowSize=6;//一行容纳多少个航班，动态的生成表格
	for(var i=1;i<=CHENKED_FLIGHTS.length;i++){
		if(i%rowSize==1){
			table.append("<tr></tr>");
		}
		$("tr:last",table).append("<td style='padding:5px 5px 5px 0px;border-bottom:0px;'>"
		+"<input type='checkbox' name='compareFlights' value='"+CHENKED_FLIGHTS[i-1]+"' checked='checked'  onclick='changeChecked(this)'/>&nbsp&nbsp"+CHENKED_FLIGHTS[i-1]
		+"</td>");
	}
}

//改变选项
function changeChecked(e){
	if($(e).attr("checked")!=true){//不选则删除他，同时需要改变select的显示方式还有全局变量
		var str=CHENKED_FLIGHTS.join("|");
		str=str.replace($(e).val(),"");
		var strs=str.split("|");
		CHENKED_FLIGHTS=[];
		for(var i=0;i<strs.length;i++){
			if(strs[i]!=null && $.trim(strs[i])!="" && strs[i]!="|"){
				CHENKED_FLIGHTS.push(strs[i]);
			}
		};
		showCheckedFlightData();
	}
}
//重置form
function resetForm(){
	$('#flightStartDate').val(generateTimeByFutrueDay(0));
	$('#flightEndDate').val(generateTimeByFutrueDay(30));
	$("#depCity").val("中文/拼音");
	$("#arrCity").val("中文/拼音");
	$("input[name='flightDateRadio'][type='radio'][value='1']").attr('checked',true);
	$("#futureDay").val("");
	$("#dataSourceHbaseKey")[0].selectedIndex=0;
	CHENKED_FLIGHTS=[];
	var table=$("#checked_flights_table");
	$(table).empty();
}

</script>

</head>
<body>
<jsp:include page="../../inc/treelist3.jsp"></jsp:include>
<jsp:include page="/pages/system/feedback/feedback.jsp" ></jsp:include>
<div class="main main_max minhgt450">
	<div class="sideBar">
	<div class="box">
		<div class="location">当前位置： 实时运价走势 &gt; 航班走势对比</div>
	</div>
	</div>
<div class="cls"></div>
<div class="content"> 
<div class="form_table_tltle">查询条件 </div>
<form id="queryForm"  method="post">

		<table cellSpacing=0 cellPadding=0 width="100%" border=0 class="form_table">
		  <tr>
		  	<TD width="120" height="26" class="left" style="text-align:left">航空公司：</TD>
		   <TD>
		   	<%-- 整个select模版，有抓取的所有航空公司，目前锁定自己所在的航空公司 --%>
		     	<select class="easyui-" name="" style="width: 150px;" id="" disabled='disabled'>
					<c:forEach var="item" items="${crawlCompanys}">
						<option value="${item.hbaseKey}"
						<c:if test="${item.hbaseKey==sessionScope.currentUser.sourceId}">selected='selected' </c:if>
						>${item.name}</option>
					</c:forEach>
				</select>
			<span style="color: #ff0000">*</span> 
		   </TD>
		   <td></td><td></td>
		 </tr>
		 <TR>
		    <TD width="120" height="26" class="left" style="text-align:left">航&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;线：</TD>
		     <TD>
		     <jsp:include page="/inc/flightSelect.jsp"></jsp:include>
		     <%-- <input type="text" name="fromCityName" style="width:100px" id="fromCityName" readonly='readonly'/>
		     <span>至</span>
		     <input type="text" name="toCityName" style="width:100px" id="toCityName" readonly='readonly'/>
		     <span style="color: #ff0000">*</span> --%>
		   </TD>
		   <td></td><td></td>
		   
		 </TR>
		 <TR>
			  <TD height="26" class="left" style="text-align:left">
			  	<input id="" name="flightDateRadio"  checked="chencked" type="radio"  value="1">航班日期：
			  </TD>
			  <TD>
			     <input name="flightStartDate" type="text" id="flightStartDate" style="width:100px"
			      onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',minDate: '%y-%M-%d',maxDate:'%y-%M-#{%d+30}'});">
			     <span>至</span>
			     <input name="flightEndDate" type="text" id="flightEndDate" style="width:100px" 
			      onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',minDate: '%y-%M-%d',maxDate:'%y-%M-#{%d+30}'});">
			      <span style="color: #ff0000">*</span>
			  </TD>
		      <TD class="left" style="text-align:left">
		      <input id="" name="flightDateRadio"   type="radio" value="2">未来天数：</TD>
		 	<TD>
		 	 <input type="text" style="width:30px" maxlength="2" 
		 	 name="futureDay" id="futureDay"  onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">天
		 	</TD>
		 </TR>  
		 <TR>
		 	<TD height="26" class="left" style="text-align:left">比较航班：</TD>
		 	<TD colspan=3>  
		 	  <table id="checked_flights_table"></table>
		 	  <!--   
		 	  <input name=compareFlights type="text" id="compareFlights" style="width:250px" value='CA1301,CA1309'>&nbsp;&nbsp;
		 	  -->	 
		 	  <input type="button" value="" class="btn07" id="Submit2" onclick="showFlightinfoPage();"/>
		 	</TD>  	
		 </TR>
		 <TR>
		   <TD class="left" style="text-align:left">数据来源:</TD>
		   <TD colspan="3">
		    	<select id="dataSourceHbaseKey" name="dataSourceHbaseKey" style="width: 150px;" id="dataSourceHbaseKey">				
					<option value="">航空公司官网</option>
					<c:forEach var="item" items="${crawlChannels}">
						<option value="${item.hbaseKey}">${item.name}</option>
					</c:forEach>	
			    </select>		
		  </TD>
		 </TR>
		 <TR>
		   <TD style="text-align:center;height:35px;line-height:35px;" colspan="4">
		     <input type="button" value="" class="btn01" id="Submit2" onclick="javascript:queryValidate();" />
		     <input type="button" name="Submit222" value="" class="btn02" onclick="javascript:resetForm();" id="Submit222" />
		   </TD>
		 </TR>
      </TABLE>
</form>

<p></p>

<p></p>
<div id="chartContainer" style="padding-bottom: 5px; width: 990px; height: 400;"></div>

</div>
</div>
<br><br><br><br><br><br><br><br><br><br>
<jsp:include page="../../inc/footer2.jsp"></jsp:include> 
</body>
</html>

